package com.example.entity;

import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class OrderDetail {
    int id;
    String date;
    double price;
    int passengers;
    String status;  //unpaid、paid、completed、cancelled、refund
    String statusText;  //待支付、已支付、已完成、已取消、退款中
    String paymentMethod;
    String paymentDate;
    String paymentDeadline;
    String cancelDate;
    String refundDate;
    //passenger
    String passenger_name;
    String passenger_sex;
    String ID_type;
    String passenger_ID_card;
    int passenger_age;
    String type;
    //flight
    int f_id;
    String departure_airport;
    String arrival_airport;
    String departure_city;
    String arrival_city;
    String departure_date;
    String departure_day;
    String departure_time;
    String arrival_date;
    String arrival_day;
    String arrival_time;
    double distance;
    String baggage_limit;
    String meal;
    String meal_money;
    //plane
    int plane_id;
    String p_model;
    String p_airline;
    int plane_age;
    String WiFi;
    int capacity;
    int economy_seat;
    int first_seat;
    int business_seat;

    public String getOrder_id() {
        return "HLTH"+date.replace("-","")+"-"+String.format("%04d", id);
    }
    public String getDuration() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("HH:mm");
            Date dep = format.parse(getDeparture_time());
            Date arr = format.parse(getArrival_time());
            long diff = arr.getTime() - dep.getTime();
            long minutes = diff / (60 * 1000); // 转换为分钟
            long hours = minutes / 60;
            minutes = minutes % 60;
            return hours + "h " + minutes + "m";
        } catch (Exception e) {
            return "N/A"; // 出错时返回默认值
        }
    }

}
